from dataclasses import dataclass
from typing import Optional

n = int(input())
other = list(map(int, input().split()))
mid = list(map(int, input().split()))


@dataclass
class Node:
    val: int
    left: Optional['Node'] = None
    right: Optional['Node'] = None


def buildT_back(back0: list, inO: list):
    if len(inO) == 0:
        return None
    else:
        root = Node(back0[-1])
        index = inO.index(back0[-1])
        root.left = buildT_back(back0[:index], inO[:index])
        root.right = buildT_back(back0[index:-1], inO[index + 1:])
        return root



tree = buildT_back(other, mid)
list2 = []


def bfs(root: Node):
    from collections import deque
    d = deque()
    d.append(root)
    while len(d) != 0:
        root = d.popleft()
        list2.append(root.val)
        if root.left:
            d.append(root.left)
        if root.right:
            d.append(root.right)


bfs(tree)
print(*list2)
